<?php

namespace App\Http\Controllers\Plugin;

use App\Exports\UsersExport;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;
use Modules\Common\Entities\User;
use DB;
class ExportController extends Controller
{
    //
    public function export(){
        //$data = User::whereNotNull('parent_id')->select('parent_id',DB::raw('count(*) as num'))->groupBy('parent_id')->get();
        //$filename = '用户' . date('Y-m-d H_i');
        //dd($data->toArray());
        return Excel::download(new UsersExport(18606898899),'user.xlsx');
    }
//    public function user(){
//        //$course_list 需要打印的课程列表
//        $course_list = [];
//        $filename = '结算账单' . date('Y-m-d H_i');
//        Excel::create($filename, function($excel) use ($course_list) {
//            $data[] = ["结算账单"];
//            $data[] = ['收入来源：课程结算'];
//            $data[] = ['结算周期：2019.09-2019.10';
//            $data[] = ['结算时间：2019.09.25'];
//            $data[] = ['课程名称', '课程ID','主讲人','主讲人uid','价格(¥)', '会员总数', '获利金额(¥)'];
//
//            foreach ($course_list as $key=>$course) {
//                $data[] = '$item_info';
//            }
//
//            $excel->sheet('课程结算账单', function ($sheet) use ($data, '$width_list') {
//                //第一行到第四行合并单元格
//                $sheet->mergeCells("A1:G1");
//                $sheet->mergeCells("A2:G2");
//                $sheet->mergeCells("A3:G3");
//                $sheet->mergeCells("A4:G4");
//
//                //第一行标题居中、加粗、设置字符大小
//                $sheet->cells("A1:G1", function ($cells) {
//                    $cells->setAlignment('center');
//                    $cells->setFontWeight('bold');
//                    $cells->setFontSize(20);
//                });
//
//                //子标题文字居中、背景色设置、加粗
//                $sheet->cells("A5:G5", function($cells) {
//                    $cells->setAlignment('center');
//                    $cells->setBackground('#C8EAFF');
//                    $cells->setFontWeight('bold');
//                    $cells->setFontSize(16);
//                });
//
//                //剩下单元格设置
//                $sheet->fromArray($data, null, 'A1', false, false)->setFontSize(16);
//            });
//
//        })->export('xlsx');
//    }
}
